#!/usr/bin/env python3  /*设定脚本文件直接能执行*/
# -*- coding:utf-8 -*-   /*设置编码*/
"""
@Author: WANDERSON M.PIMENTA
@Software: PyCharm 、Qt Designer and PySide6
@File: tJsonThemes.py
@Time: 2024/05/11 16:08
@Function：应用程序加载主题文件（Json文件）：加载主题文件(Json),UI/themes目录下，目前有三种主题：dracula、default、bright_theme
"""
import json
import os
from UI.cores.tJsonSettings import Settings


# APP THEMES
class Themes(object):
    """
    加载主题文件(Json),UI/themes目录下，目前有三种主题：dracula、default、bright_theme
    """
    # 加载设置文件
    setup_settings = Settings()
    _settings = setup_settings.items

    # Json文件地址
    json_file = f"UI/themes/{_settings['theme_name']}.json"
    app_path = os.path.abspath(os.getcwd())
    settings_path = os.path.normpath(os.path.join(app_path, json_file))
    if not os.path.isfile(settings_path):
        print(f"WARNING: \"UI/themes/{_settings['theme_name']}.json\" not found! check in the folder {settings_path}")

    # 初始化
    def __init__(self):
        super(Themes, self).__init__()
        # 初始化带设置的字典
        self.items = {}
        # 反序列化
        self.deserialize()

    # 序列化Json文件
    def serialize(self):
        # 写入Json文件
        with open(self.settings_path, "w", encoding='utf-8') as write:
            json.dump(self.items, write, indent=4)

    # 反序列化Json文件
    def deserialize(self):
        # 读取Json文件
        with open(self.settings_path, "r", encoding='utf-8') as reader:
            settings = json.loads(reader.read())
            self.items = settings
